import Item from "./owner/item";
import { guid } from "@libs";
import { addData } from "@store/data";

export const addList = (lists, item = {}) => {
    const uuid = guid();
    const data = new Item();
    data.uuid = uuid;
    for(let p in item){
        data[p] = item[p];
    }
    addData(uuid, data);
    return [...lists, data];
}

export const updateList = (lists, data) => {
    const { uuid } = data;
    for(let i = 0, l = lists.length;i < l;i++){
        const d = lists[i];
        if(d.uuid === uuid){
            lists[i] = data;
            break;
        }
    }
    return [...lists];
}

export const removeList = (lists, data) => {
    const { uuid } = data;
    const ds = lists.filter(e => e.uuid !== uuid);
    return [...ds];
}